# from core.characters.mage_female.elementalist import classChange
# from core.equipment.version_0 import effectsList

# char = classChange()
# skill = char.GetSkillByName('冰霜雪人')
# char.SetDetail({
#   "weapon":{
#     "id":"2006030069",
#     "reinforce":20,
#     "enchant":"2345",
#     "emblems":["3456","4567"],
#     "seal":["5678","6789"]
#   }
# })
# char.calc()

# print(char.PDamageC,char.PINT)
import re

import json
from routers.database.db import Session,get_engine,SuitData
calEqus = []
iEid = -1

with open("./suits.json", encoding='utf-8') as fp:
    info = json.load(fp)

def getDesc(a):
    res = []
    p_contents = re.findall(r'<p>(.*?)</p>', a['extraInfo'])
    nums = re.findall(r'\[(\d+)\]套装效果', a['extraInfo'])
    for i in p_contents:
        temp = re.findall(r'<span.*?>(.*?)</span>', i)
        if len(temp) == 0 :
            if i == '':
                temp = ['']
            else:
                 temp = [i]
        res += temp
    index = [i for i, item in enumerate(res) if '套装效果' in item]
    resList = []
    for i,item in enumerate(index):
        if i == len(index) - 1:
            resList.append(('<br>').join(res[item+1:]))
        else:
            resList.append(('<br>').join(res[item+1:index[i+1]]))
    return (nums,resList)
      

engine = get_engine("0")
id = 1
with Session(bind=engine) as session:
    # calEqus = session.query(EquipmentData).all()
    # info = list(filter(lambda x:x['name'] == "魂 · 暗夜潜行者",info))
    for i in info:
        # print(i['name'].replace(" ",""))
        des = getDesc(i)
        print(des)
        for index in range(0,len(des[0])):
            temp = SuitData()
            temp.id = id
            temp.suitID = i['id']
            temp.suitName = i['name']
            temp.needNum = int(des[0][index])
            temp.desc = des[1][index]
            id += 1
            session.add(temp) 
    session.commit()
engine.dispose()
